package com.anyou.mall.fin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.mall.fin.vo.GetTotalVo;
import com.anyou.mall.fin.vo.TrendChartVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.fin.domain.PlatformReconciliation;
import com.anyou.mall.fin.service.IPlatformReconciliationService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 平台对账Controller
 *
 * @author gaochaohao
 * @date 2022-04-19
 */
@Api(tags = "平台对账")
@RestController
@RequestMapping("/fin/platformReconciliation")
public class PlatformReconciliationController extends BaseController
{
    @Autowired
    private IPlatformReconciliationService platformReconciliationService;

    /**
     * 查询平台对账列表
     */
    @ApiOperation("查询平台对账列表")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:list')")
    @GetMapping("/list")
    public TableDataInfo<List<PlatformReconciliation>> list(PlatformReconciliation platformReconciliation)
    {
        startPage();
        List<PlatformReconciliation> list = platformReconciliationService.selectPlatformReconciliationList(platformReconciliation);
        return getDataTable(list);
    }

    /**
     * 导出平台对账列表
     */
    @ApiOperation("导出平台对账列表")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:export')")
    @Log(title = "平台对账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlatformReconciliation platformReconciliation)
    {
        List<PlatformReconciliation> list = platformReconciliationService.selectPlatformReconciliationList(platformReconciliation);
        ExcelUtil<PlatformReconciliation> util = new ExcelUtil<PlatformReconciliation>(PlatformReconciliation.class);
        util.exportExcel(response, list, "平台对账数据");
    }

    /**
     * 获取平台对账详细信息
     */
    @ApiOperation("获取平台对账详细信息")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:query')")
    @GetMapping(value = "/{platformReconciliationId}")
    public ApiResult<PlatformReconciliation> getInfo(@PathVariable("platformReconciliationId") Long platformReconciliationId)
    {
        return ApiResult.success(platformReconciliationService.selectPlatformReconciliationByPlatformReconciliationId(platformReconciliationId));
    }

    /**
     * 新增平台对账
     */
    @ApiOperation("新增平台对账")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:add')")
    @Log(title = "平台对账", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody PlatformReconciliation platformReconciliation)
    {
        return ApiResult.success(platformReconciliationService.insertPlatformReconciliation(platformReconciliation));
    }

    /**
     * 修改平台对账
     */
    @ApiOperation("修改平台对账")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:edit')")
    @Log(title = "平台对账", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody PlatformReconciliation platformReconciliation)
    {
        return ApiResult.success(platformReconciliationService.updatePlatformReconciliation(platformReconciliation));
    }

    /**
     * 删除平台对账
     */
    @ApiOperation("删除平台对账")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:remove')")
    @Log(title = "平台对账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{platformReconciliationIds}")
    public ApiResult remove(@PathVariable Long[] platformReconciliationIds)
    {
        return ApiResult.success(platformReconciliationService.deletePlatformReconciliationByPlatformReconciliationIds(platformReconciliationIds));
    }

    /**
     * 查询平台对账汇总
     */
    @ApiOperation("查询平台对账汇总")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:total')")
    @GetMapping("/total")
    public ApiResult<GetTotalVo> getTotal() {
        return platformReconciliationService.getTotal();
    }

    /**
     * 平台资金池金额变化趋势图数据
     */
    @ApiOperation("平台资金池金额变化趋势图数据")
    @PreAuthorize("@ss.hasPermi('fin:platformReconciliation:trendChart')")
    @GetMapping("/trendChart/{selectTime}")
    public ApiResult<List<TrendChartVo>> trendChart(@PathVariable("selectTime") String selectTime) {
        return platformReconciliationService.trendChart(selectTime);
    }
}
